<html>
	<head>
		<title>随机星星</title>
		<meta charset="utf-8">
		<script>
			window.onload = init;
			function init() {
				document.body.bgColor="#000";
				//定时器
				window.setInterval("star()", 1000);
			}
			//动画主函数
			function star() {
				var imgObj = document.createElement("img");
				//添加图片
				imgObj.setAttribute("src", "image/day6/xingxing.gif");
				//添加width属性
				var width = getRandom(15, 85);
				imgObj.setAttribute("width", width);
				//位置参数
				var X = getRandom(0, window.innerWidth);
				var Y = getRandom(0, window.innerHeight);

    			imgObj.setAttribute("style","position:absolute;left:"+X+"px;top:"+Y+"px;");
    			//添加点击事件
    			imgObj.setAttribute("onclick", "removeImg(this)");
				//将图片节点，加载到<body>父节点上
				document.body.appendChild(imgObj);

			} 

			function getRandom(x1, x2) {
				var rand = Math.random() * (x2 - x1) + x1;
				rand = Math.floor(rand);
				return rand;
			}
			function removeImg(obj) {
				document.body.removeChild(obj);
			}
		</script>
	</head>
	<body>
		
	</body>
</html>